import request from '@/utils/request';
import { AxiosPromise } from 'axios';
import { UnitVO, UnitForm, UnitQuery } from '@/api/wmscloud/unit/types';


/**
 * 查询所有物料单位
 * @returns {*}
 */

export const listAllUnit = (): AxiosPromise<UnitVO[]> => {
  return request({
    url: '/wmsCloud/unit/listAll',
    method: 'get'
  });
};
/**
 * 查询物料单位列表
 * @param query
 * @returns {*}
 */

export const listUnit = (query?: UnitQuery): AxiosPromise<UnitVO[]> => {
  return request({
    url: '/wmsCloud/unit/list',
    method: 'get',
    params: query
  });
};
/**
 * 查询物料主单位
 * @param query
 * @returns {*}
 */

export const listPrimary = (): AxiosPromise<UnitVO[]> => {
  return request({
    url: '/wmsCloud/unit/listprimary',
    method: 'get',
  });
};
/**
 * 查询物料单位详细
 * @param unitId
 */
export const getUnit = (unitId: string | number): AxiosPromise<UnitVO> => {
  return request({
    url: '/wmsCloud/unit/' + unitId,
    method: 'get'
  });
};

/**
 * 新增物料单位
 * @param data
 */
export const addUnit = (data: UnitForm) => {
  return request({
    url: '/wmsCloud/unit',
    method: 'post',
    data: data
  });
};

/**
 * 修改物料单位
 * @param data
 */
export const updateUnit = (data: UnitForm) => {
  return request({
    url: '/wmsCloud/unit',
    method: 'put',
    data: data
  });
};

/**
 * 删除物料单位
 * @param unitId
 */
export const delUnit = (unitId: string | number | Array<string | number>) => {
  return request({
    url: '/wmsCloud/unit/' + unitId,
    method: 'delete'
  });
};
